package com.example.note;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import android.widget.TextView;


public class NotatkaAdapter extends ArrayAdapter<Notatka> {

	private Activity context;
	private List<Notatka> notes;
	public NotatkaAdapter(Activity context, List<Notatka> notes) {
		super(context, R.layout.note_list_item, notes);
		this.context = context;
		this.notes = notes;
	}

	static class ViewHolder {
		public TextView tvNoteTresc;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		View rowView = convertView;
		
		Notatka task = notes.get(position);
		
		if(rowView == null) {
			LayoutInflater layoutInflater = context.getLayoutInflater();
			rowView = layoutInflater.inflate(R.layout.note_list_item, null, true);
			viewHolder = new ViewHolder();
			viewHolder.tvNoteTresc = (TextView) rowView.findViewById(R.id.tvNoteTresc);
			rowView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) rowView.getTag();
		}
		
		viewHolder.tvNoteTresc.setText(task.getTresc());
		if(task.getPriorytet()==1) {
			//rowView = layoutInflater.inflate(R.layout.note_list_item1, null, true);
			//viewHolder.tvNoteTresc.setBackgroundColor(Color.parseColor("#99ff99"));
			rowView.setBackgroundResource(R.drawable.noteshape1);
			//rowView.setBackgroundColor(Color.parseColor("#99ff99"));
			
		} else if(task.getPriorytet()==3) {
			//viewHolder.tvNoteTresc.setBackgroundColor(Color.parseColor("#ff3333"));
			//rowView.setBackgroundColor(Color.parseColor("#ff3333"));
			rowView.setBackgroundResource(R.drawable.noteshape3);
		} else{
			//viewHolder.tvNoteTresc.setBackgroundColor(Color.parseColor("#ffff00"));
			//rowView.setBackgroundColor(Color.parseColor("#ffff00"));
			rowView.setBackgroundResource(R.drawable.noteshape2);
		}
		return rowView;
	}
}